
cmake_minimum_required(VERSION 3.22)
project(cpp_test CXX C)
message(STATUS "Building project: ${PROJECT_NAME}")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_STANDARD 11)

# message(STATUS "C++ compiler supports these features:")
# foreach(i ${CMAKE_CXX_COMPILE_FEATURES})
#   message(STATUS "${i}")
# endforeach()

# set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type")

if(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux")
	message(STATUS "current platform: Linux ")
    add_compile_options(-O0 -g)
elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
    if (MSVC)
        add_compile_options(/utf-8)
        message(STATUS "current platform: Windows Visual Studio")
    endif ()
else()
	message(STATUS "current platform: unkown")
endif()

# set(CMAKE_PREFIX_PATH libevent)
# set(LIBEVENT_STATIC_LINK TRUE)
# find_package(Libevent REQUIRED PATHS "C:/Library" NO_DEFAULT_PATH)
# if (Libevent_FOUND)
#     message(STATUS "Found libevent library !")
# endif()

set(EVENT__DISABLE_TESTS            ON)
set(EVENT__DISABLE_DOCS             ON)
set(EVENT__DISABLE_DEBUG_MODE       ON)
set(EVENT__DISABLE_OPENSSL          OFF)
set(EVENT__DISABLE_BENCHMARK        ON)
set(EVENT__DISABLE_REGRESS          ON)
set(EVENT__DISABLE_SAMPLES          ON)
set(EVENT__DISABLE_THREAD_SUPPORT   OFF)
set(EVENT__LIBRARY_TYPE             STATIC)
set(OPENSSL_ROOT_DIR "C:/openssl/OpenSSL1-Win64")
set(OPENSSL_LIBRARIES "${OPENSSL_ROOT_DIR}/lib")
set(OPENSSL_INCLUDE_DIR "${OPENSSL_ROOT_DIR}/include")
add_subdirectory(libevent)

add_subdirectory(spdlog)
file(GLOB CYGIA_LIB_SRCS library/*.cc)
add_library(local_library ${CYGIA_LIB_SRCS})
target_link_libraries(local_library PUBLIC
    spdlog::spdlog
    event_core
    # event_pthreads
    event_extra
    event_openssl
)
target_include_directories(local_library PUBLIC library)

set(SOURCE_DIR source)
file(GLOB ALL_ITEMS ${SOURCE_DIR}/*)
foreach(ITEM ${ALL_ITEMS})
    if(IS_DIRECTORY ${ITEM})
        get_filename_component(EXE_NAME ${ITEM} NAME_WE)
        message(STATUS "Target: ${EXE_NAME}")
        file(GLOB_RECURSE SOURCES ${ITEM}/*.cc ${ITEM}/*.c)
        add_executable(${EXE_NAME} ${SOURCES})
        target_link_libraries(${EXE_NAME} PUBLIC
            event_core
            event_extra
            # event_pthreads
            event_openssl
            local_library)
    endif()
endforeach()
